package com.sofwin.controller;/**
 * @PackageName:com.sofwin.controller
 * @author:andyLiu
 * @DateTime:2020/12/25 16:13
 * @Description:[TODO]输入当前模块作用
 **/

import com.github.pagehelper.PageInfo;
import com.sofwin.pojo.SRole;
import com.sofwin.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * @ClassName: RoleController
 * @Description: TODO
 * @Author: andyliu
 * @Date: 2020/12/25 16:13
 * @Version: 1.0
 **/
@Controller
@RequestMapping("/role")
public class RoleController {

    @Autowired
    RoleService roleService;
    @RequestMapping("/data")
    public String data(){
        return "role/data";
    }
    @GetMapping("/roleData")
    @ResponseBody
    public PageInfo<SRole> roleData(SRole role,@RequestParam(required = true,defaultValue = "1") Integer pageNumber){
        PageInfo<SRole> page = roleService.queryRoleByPage(role,pageNumber);
        return page;
    }
    @RequestMapping("add")
    public String add(SRole role, Model mod) {
        if (role.getId() != null) {
            role = roleService.selectOneById(role);
            mod.addAttribute("role", role);
        }
        return "role/add";
    }

    @RequestMapping("delete")
    @ResponseBody
    public boolean delete(Integer[] ids){
        boolean status = roleService.deleteRoleById(ids);


        return status;
    }

    @RequestMapping("/save")
    @ResponseBody
    public Map save(SRole role){
        Map map = roleService.saveRole(role);
        return map;
    }
}
